<template>
  <div class="kvtransformer">
    <headerc :title="title" :sshow="show"></headerc>
    <div class="c-main-make">
      <div class="title-text">数据筛选</div>
      <div class="kvtransformer-Query">
        <el-form
          :inline="true"
          label-position="left"
          :label-width="formLabelWidth"
          :model="params"
          class="demo-form-inline"
        >
          <el-form-item label="巡检人">
            <el-select
              v-model="params.Inspector"
              filterable
              remote
              @change="FnQuerySelectInspector"
              reserve-keyword
              placeholder="请输入巡检人"
              :remote-method="FnQueryInspector"
            >
              <el-option
                v-for="item in InspectorArr"
                :key="item.id"
                :label="item.emplName"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="配电室名称">
            <el-select
              remote
              :remote-method="FnQueryRoomName"
              v-model="params.roomName"
              filterable
              @change="FnQuerySelectRoomName"
              placeholder="请搜索选择配电室"
            >
              <el-option
                v-for="item in roomList"
                :key="item.id"
                :label="item.roomName"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="巡检时间">
            <el-date-picker
              v-model="params.inspectionTime"
              align="right"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择巡检时间"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="是否上报">
            <el-select v-model="params.noticeLeader" placeholder="请选择">
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item style="float: right">
            <el-button type="primary" icon="el-icon-search" @click="FnQuery"
              >查询</el-button
            >
          </el-form-item>
          <el-form-item style="float: right">
            <el-button type="primary" @click="FnReset">清除查询条件</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>






    <div class="c-main-show">
      <div class="main-seting">
        <div>
          <div class="title-text">巡检记录列表</div>
          <el-button
            v-auth="'B02004'"
            type="primary"
            style="
              float: right;
              margin-right: 20px;
              margin-bottom: 20px;
              margin-top: 20px;
            "
            @click="exportExcel"
            >导出</el-button
          >
          <el-button
            v-auth="'B02001'"
            icon="el-icon-circle-plus-outline"
            type="primary"
            @click="FnOpenDialog(1)"
            style="
              float: right;
              margin-right: 20px;
              margin-bottom: 20px;
              margin-top: 20px;
            "
            >新增</el-button
          >

          <!-- 新增或编辑 -->
          <el-dialog
            width="40%"
            :title="dialogTitle"
            :visible.sync="dialog"
            :close-on-click-modal="false"
          >
            <el-form
              :model="formEdit"
              :rules="rules"
              ref="createForm"
              :label-position="labelPosition"
            >
              <!-- 是否上报班组长 -->
              <el-form-item
                label="是否上报班组长"
                :label-width="formLabelWidth"
              >
                <el-select
                  v-if="dialogTitle == '新增巡检记录'"
                  @change="FnSelectLeader"
                  v-model="formEdit.noticeLeader"
                  style="width: 88%"
                  placeholder="请选择"
                >
                  <el-option label="是" :value="1"></el-option>
                  <el-option label="否" :value="0"></el-option>
                </el-select>
                <el-input
                  style="width: 88%"
                  v-if="dialogTitle == '更新巡检记录'"
                  disabled
                  v-model="formEdit.noticeLeader"
                ></el-input>
              </el-form-item>
              <!-- 巡检人 -->
              <el-form-item
                label="巡检人"
                :label-width="formLabelWidth"
                prop="empIds"
              >
                <el-select
                  filterable
                  remote
                  reserve-keyword
                  style="width: 88%"
                  :remote-method="FnSearchMember"
                  @change="changeInspector"
                  v-model="formEdit.Inspector"
                  clearable
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in InspectorArr"
                    :key="item.id"
                    :label="item.emplName"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
                <div></div>
              </el-form-item>
              <!-- 巡检时间 -->
              <el-form-item
                label="巡检时间"
                :label-width="formLabelWidth"
                prop="inspectionTime"
              >
                <el-input
                  disabled
                  style="width: 88%"
                  v-model="formEdit.inspectionTime"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <!-- 巡检位置 -->
              <el-form-item
                label="巡检位置"
                :label-width="formLabelWidth"
                prop="pdroomName"
              >
                <el-select
                  style="width: 88%"
                  v-model="formEdit.pdroomName"
                  remote
                  reserve-keyword
                  filterable
                  @change="FnSelectRoom"
                  placeholder="请输入巡检位置"
                  :remote-method="remoteRoomName"
                >
                  <el-option
                    v-for="item in roomList"
                    :key="item.id"
                    :label="item.roomName"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <!-- 编号 -->
              <el-form-item
                label="编号"
                :label-width="formLabelWidth"
                prop="num"
              >
                <el-input  style="width: 88%" v-model="formEdit.num" placeholder="请输入编号" @input="FnSelectNum"></el-input>
              </el-form-item>

              <el-form-item
                label="线路名称"
                :label-width="formLabelWidth"
                prop="lineName"
              >
                <el-input
                  disabled
                  style="width: 88%"
                  v-model="formEdit.lineName"
                  autocomplete="off"
                ></el-input>
              </el-form-item>

              <el-form-item
                label="电压A"
                :label-width="formLabelWidth"
                prop="voltageA"
              >
                <el-input
                  style="width: 88%"
                  v-model="formEdit.voltageA"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="电压B"
                :label-width="formLabelWidth"
                prop="voltageB"
              >
                <el-input
                  v-model="formEdit.voltageB"
                  style="width: 88%"
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="班次"
                :label-width="formLabelWidth"
                prop="dayShift"
              >
                <el-select
                  v-model="formEdit.dayShift"
                  style="width: 88%"
                  placeholder="请选择"
                >
                  <el-option label="白班" :value="1"></el-option>
                  <el-option label="夜班" :value="0"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item
                label="电压C"
                :label-width="formLabelWidth"
                prop="voltageC"
              >
                <el-input
                  style="width: 88%"
                  v-model="formEdit.voltageC"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="电流A"
                :label-width="formLabelWidth"
                prop="currentA"
              >
                <el-input
                  style="width: 88%"
                  v-model="formEdit.currentA"
                  autocomplete="off"
                ></el-input>
              </el-form-item>

              <el-form-item
                label="电流C"
                :label-width="formLabelWidth"
                prop="currentC"
              >
                <el-input
                  style="width: 88%"
                  v-model="formEdit.currentC"
                  autocomplete="off"
                ></el-input>
              </el-form-item>

              <el-form-item label="备注" :label-width="formLabelWidth">
                <el-input
                  type="textarea"
                  style="width: 88%"
                  v-model="formEdit.remark"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="FnNext(2)">下一组</el-button>
              <el-button
                v-if="dialogTitle == '更新巡检记录'"
                type="primary"
                @click="FnUpdate"
              >
                更 新</el-button
              >
              <el-button
                v-if="dialogTitle == '新增巡检记录'"
                type="primary"
                @click="FnSave(1)"
              >
                提交</el-button
              >
            </div>
          </el-dialog>
          

           <!-- 查看 -->
          <el-dialog
            width="40%"
            :title="dialogTitle"
            :visible.sync="dialog"
            :close-on-click-modal="false"
          >
            <el-form
              :model="formEdit"
              :rules="rules"
              ref="createForm"
              :label-position="labelPosition"
            >
              <!-- 是否上报班组长 -->
              <el-form-item
                label="是否上报班组长"
                :label-width="formLabelWidth"
              >
                <el-select
                  v-if="dialogTitle == '新增巡检记录'"
                  @change="FnSelectLeader"
                  v-model="formEdit.noticeLeader"
                  style="width: 88%"
                  placeholder="请选择"
                >
                  <el-option label="是" :value="1"></el-option>
                  <el-option label="否" :value="0"></el-option>
                </el-select>
                <el-input
                  style="width: 88%"
                  v-if="dialogTitle == '更新巡检记录'"
                  disabled
                  v-model="formEdit.noticeLeader"
                ></el-input>
              </el-form-item>
              <!-- 巡检人 -->
              <el-form-item
                label="巡检人"
                :label-width="formLabelWidth"
                prop="empIds"
              >
                <el-select
                  filterable
                  remote
                  reserve-keyword
                  style="width: 88%"
                  :remote-method="FnSearchMember"
                  @change="changeInspector"
                  v-model="formEdit.Inspector"
                  clearable
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in InspectorArr"
                    :key="item.id"
                    :label="item.emplName"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
                <div></div>
              </el-form-item>
              <!-- 巡检时间 -->
              <el-form-item
                label="巡检时间"
                :label-width="formLabelWidth"
                prop="inspectionTime"
              >
                <el-input
                  disabled
                  style="width: 88%"
                  v-model="formEdit.inspectionTime"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <!-- 巡检位置 -->
              <el-form-item
                label="巡检位置"
                :label-width="formLabelWidth"
                prop="pdroomName"
              >
                <el-select
                  style="width: 88%"
                  v-model="formEdit.pdroomName"
                  remote
                  reserve-keyword
                  filterable
                  @change="FnSelectRoom"
                  placeholder="请输入巡检位置"
                  :remote-method="remoteRoomName"
                >
                  <el-option
                    v-for="item in roomList"
                    :key="item.id"
                    :label="item.roomName"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <!-- 编号 -->
              <el-form-item
                label="编号"
                :label-width="formLabelWidth"
                prop="num"
              >
                <el-input  style="width: 88%" v-model="formEdit.num" placeholder="请输入编号" @input="FnSelectNum"></el-input>
              </el-form-item>

              <el-form-item
                label="线路名称"
                :label-width="formLabelWidth"
                prop="lineName"
              >
                <el-input
                  disabled
                  style="width: 88%"
                  v-model="formEdit.lineName"
                  autocomplete="off"
                ></el-input>
              </el-form-item>

              <el-form-item
                label="电压A"
                :label-width="formLabelWidth"
                prop="voltageA"
              >
                <el-input
                  style="width: 88%"
                  v-model="formEdit.voltageA"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="电压B"
                :label-width="formLabelWidth"
                prop="voltageB"
              >
                <el-input
                  v-model="formEdit.voltageB"
                  style="width: 88%"
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="班次"
                :label-width="formLabelWidth"
                prop="dayShift"
              >
                <el-select
                  v-model="formEdit.dayShift"
                  style="width: 88%"
                  placeholder="请选择"
                >
                  <el-option label="白班" :value="1"></el-option>
                  <el-option label="夜班" :value="0"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item
                label="电压C"
                :label-width="formLabelWidth"
                prop="voltageC"
              >
                <el-input
                  style="width: 88%"
                  v-model="formEdit.voltageC"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="电流A"
                :label-width="formLabelWidth"
                prop="currentA"
              >
                <el-input
                  style="width: 88%"
                  v-model="formEdit.currentA"
                  autocomplete="off"
                ></el-input>
              </el-form-item>

              <el-form-item
                label="电流C"
                :label-width="formLabelWidth"
                prop="currentC"
              >
                <el-input
                  style="width: 88%"
                  v-model="formEdit.currentC"
                  autocomplete="off"
                ></el-input>
              </el-form-item>

              <el-form-item label="备注" :label-width="formLabelWidth">
                <el-input
                  type="textarea"
                  style="width: 88%"
                  v-model="formEdit.remark"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <!-- <el-button @click="FnNext(2)">下一组</el-button> -->
              <el-button
                v-if="dialogTitle == '更新巡检记录'"
                type="primary"
                @click="FnUpdate"
              >
                更 新</el-button
              >
              <el-button
                v-if="dialogTitle == '新增巡检记录'"
                type="primary"
                @click="FnSave(1)"
              >
                提交</el-button
              >
            </div>
          </el-dialog>

          <div style="margin: 20px">
            <el-table :data="tableData" border style="width: 100%">
              <el-table-column width="170" label="巡检日期">
                <template slot-scope="scope">
                  <span>{{ timefun(scope.row.inspectionTime) }}</span>
                </template>
              </el-table-column>
              <el-table-column prop="dayShift" label="班次" width="100px">
                 <template slot-scope="scope">
                  <span>{{ scope.row.dayShift ? "白班" : "夜班" }}</span>
                </template>
              </el-table-column>
              <el-table-column prop="num" label="编号">
              </el-table-column>
              <el-table-column prop="lineName" label="线路名称">
              </el-table-column>
              <el-table-column prop="voltageA" label="电压A">
              </el-table-column>
              <el-table-column prop="voltageB" label="电压B">
              </el-table-column>
              <el-table-column prop="voltageC" label="电压C">
              </el-table-column>
              <el-table-column prop="currentA" label="电流A">
              </el-table-column>
            <el-table-column prop="currentC" label="电流C">
              </el-table-column>

             

              <el-table-column label="是否上报">
                <template slot-scope="scope">
                  <span>{{ scope.row.noticeLeader ? "是" : "否" }}</span>
                </template>
              </el-table-column>

              <el-table-column label="状态">
                <template slot-scope="scope">
                  <span v-if="scope.row.noticeLeader && scope.row.leaderDeal"
                    >已处理</span
                  >
                  <span v-if="scope.row.noticeLeader && !scope.row.leaderDeal"
                    >待处理</span
                  >
                  <span v-if="!scope.row.noticeLeader">正常</span>
                </template>
              </el-table-column>

              <el-table-column label="巡检人" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                  <span
                    style="
                      overflow: hidden;
                      text-overflow: ellipsis;
                      white-space: nowrap;
                      width: 100px;
                    "
                    >{{ scope.row.empNames }}</span
                  >
                </template>
              </el-table-column>
              <el-table-column prop="remark" label="备注"> </el-table-column>
              <el-table-column
                prop="num"
                label="操作"
                width="150px"
                fixed="right"
              >
                <template slot-scope="scope">
                  <el-button
                    @click="FnDeal(scope.row)"
                    type="text"
                    size="small"
                    v-show="scope.row.noticeLeader && !scope.row.leaderDeal"
                    >待处理</el-button
                  >
                  <el-button
                    v-auth="'B02003'"
                    @click="handleClick(scope.row)"
                    type="text"
                    size="small"
                    >编辑</el-button
                  >

                    <!-- <el-button
                    @click="FnJumpToDetail(scope.row)"
                    type="text"
                    size="small"
                    >查看</el-button
                  > -->
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="fenye">
            <el-pagination
              background
              layout="prev, pager, next"
              :page-size="pageSize"
              :total="total"
              :current-page.sync="currentPage"
              :hide-on-single-page="total < 10"
              @current-change="currentChange"
              style="margin-left: 25%"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import headerc from "@/components/header.vue";
import { exportMethod, getTime } from "@/utils/utils";
import {
  kvoperationadd,
  kvoperationGetById,
  pdroomByParam,
  pdroomgetAllByRoomName,
  getlists,
  kvoperationDeal,
  modelNameIndex,
  kvoperationupdate,
  kvoperationaddNextLine,
  kvoperationDealAllException,
  kvoperationlist,
} from "../../../api/patrol-record";
import utils from "@/utils/utils";
export default {
  components: {
    headerc,
  },
  data() {
    return {
      //当前登录人是否有班组长 默认都是有
			leader:true,
      currentPage: 1,
      labelPosition: "left",
      title: "10kv操作室巡检记录",
      empIdsList: [],
      dialogTitle: "",
      restaurants: [],
      restaurants2: [],
      state: "",
      timeout: null,
      uid: "",
      updata: 1,
      pageNo: 1,
      pageSize: 10,
      total: 0,
      dialog: false,
      rules: {
        noticeLeader: [
          {
            required: true,
            message: "是否上报班组长不能为空",
            trigger: "blur",
          },
        ],
        empIds: [
          {
            required: true,
            message: "巡检人不能为空",
            trigger: "blur",
          },
        ],
        inspectionTime: [
          { required: true, message: "巡检时间不能为空", trigger: "blur" },
        ],
        roomId: [
          {
            required: true,
            message: "巡检位置不能为空",
            trigger: "blur",
          },
        ],
        dayShift: [
          { required: true, message: "班次不能为空", trigger: "blur" },
        ],

        pdroomId: [
          { required: true, message: "编号不能为空", trigger: "blur" },
        ],
        voltageA: [
          {
            required: true,
            message: "电压A不能为空",
            trigger: "blur",
          },
        ],
        voltageB: [
          {
            required: true,
            message: "电压B不能为空",
            trigger: "blur",
          },
        ],
        voltageC: [
          {
            required: true,
            message: "电压C不能为空",
            trigger: "blur",
          },
        ],
        currentA: [
          {
            required: true,
            message: "电流A不能为空",
            trigger: "blur",
          },
        ],
        currentC: [
          {
            required: true,
            message: "电流C不能为空",
            trigger: "blur",
          },
        ],
        num:[
          {
            required: true,
            message: "编号不能为空",
            trigger: "blur",
          },
        ],
        pdroomName: [
          {
            required: true,
            message: "线路名称",
            trigger: "blur",
          },
        ]
      },
      roomList: [],
      // 表单
      formEdit: {
        id: "",
        inspectionTime: "",
        empIds: "",
        empNames:'',
        Inspector: "",
        remark: "",
        roomId: "",
        roomName: "",
        num: "",
        pdroomName: "",
        pdroomId: "",
        lineName:'',
        noticeLeader: "",
        creatorId: "",
        questionResult: "",
        leaderDeal: 0,
        //电压A
        voltageA: "",
        //电压B
        voltageB: "",
        //电压c
        voltageC: "",
        //电流A
        currentA: "",
        //电流C
        currentC: "",
        // 备注
        remark: "",
        pdroomId: "",
        recordSeq: 1,
        recordCode: "",
      },
      formLabelWidth: "180px",
      show: true,
      InspectorArr: [],
      // 巡检位置数组
      roomList: [],
      params: {
        //巡检人
        empId: "",
        //巡检位置
        roomName: "",
        roomId: "",
        // 巡检时间
        inspectionTime: "",
        noticeLeader: "",

        //变压器有无异响
      },
      formInline: {
        user: "",
        region: "",
        value1: "",
        mingcheng: "",
        noticeLeader: "",
        empIds: "",
        roomName: "",
      },
      tableData: [],
      InspectorArr: [],
    };
  },
  created() {
    let params = {
      pageNo: 1,
      pageSize: 10,
    };
    this.getkvoperationlist(params);
  },
  methods: {
    // 查看页面
    FnJumpToDetail(){

    },
    // 选择线路
    FnSelectNum(val) {
      console.log(val);
      pdroomByParam({
        num: val,
        recordType: "2",
      }).then((res) => {
        if (res.code == "200") {
          console.log(res)
           console.log('==res==')
           if(res.code==200&&res.data){
             this.formEdit.lineName = res.data.roomName;
             this.formEdit.pdroomId = res.data.id;
           }else{
             //校验部分表单字段
           }
          // if (res.data) {
          //   console.log(res);
          //   console.log("res");
          //   this.roomList = [res.data];
          //   this.formEdit.pdroomName = res.data.roomName;
          //   this.formEdit.pdroomId = res.data.id;
          // } else {
          //   console.log("没拿到值");
          //   this.formEdit.roomName = "";
          //   this.formEdit.pdroomId = "";
          // }
        }
      });
    },
    // 输入编号
    remoteRoomNum(val) {
      console.log(val);
      pdroomByParam({
        num: val,
        recordType: "2",
      }).then((res) => {
        if (res.code == "200") {
          if (res.data) {
            console.log(res);
            console.log("res");
            // this.formEdit.pdroomName = res.data.roomName;
            // this.formEdit.pdroomId = res.data.id;
            this.roomList = [res.data];
            this.formEdit.pdroomName = res.data.roomName;
            this.formEdit.pdroomId = res.data.id;
          } else {
            //校验 没拿到线路名称此时 提交的时候需要校验
            console.log("没拿到值");
            this.formEdit.roomName = "";
            this.formEdit.pdroomId = "";
          }
        }
      });
    },
    //筛选条件 查询配电室名字
    FnQueryRoomName(val) {
      console.log(val);
      console.log("===val===");
      pdroomgetAllByRoomName({
        roomName: val,
        recordType: 2,
      }).then((res) => {
        console.log(res);
        console.log("===res===");
        if (res.code == 200) {
          this.roomList = res.data;
        }
      });
    },
    // 选择配电室
    FnQuerySelectRoomName(val) {
      console.log(val);
      this.params.roomId = val;
    },
    //选择巡检人
    FnQuerySelectInspector(val) {
      this.params.empId = val;
    },
    // 查询条件
    FnQueryInspector(val) {
      getlists({
        deptId: "",
        emplName: val,
        userType: "1",
      }).then((res) => {
        this.InspectorArr = res.data;
        console.log(this.InspectorArr);
      });
    },
    FnSelectLeader(val) {
      console.log(val);
    },
    //选择
    FnSelectRoom(val) {
      console.log(val);
      console.log("===val===");
      // this.formEdit.roomId = val;
      this.formEdit.pdroomId = val
      this.roomList = []
    },
    //表单 查配电室
    remoteRoomName(val) {
      console.log(val);
      //模糊查询配电室名称
      pdroomgetAllByRoomName({
        roomName: val,
        recordType: 2,
      }).then((res) => {
        console.log(res);
        console.log("===res===");
        if (res.code == 200) {
          this.roomList = res.data;
        }
      });
    },
    //保存
    FnSave(val) {
        // 如果 上报了异常 并且 这个人没有班组长
				if((!this.leader) && (!this.form.noticeLeader)){
					//给提示信息
					this.$message({
              message: '没有班组长',
              type: 'error',
            })
					return 
				}





      console.log(this.formEdit);
      this.$refs.createForm.validate((valid) => {
        if (valid) {
          this.formEdit.noticeLeader==1?this.formEdit.noticeLeader=1:this.formEdit.noticeLeader=0
          kvoperationadd(this.formEdit).then((res) => {
            console.log(res);
            if (res.code == "200") {
              this.formEdit.recordCode = res.data.recordCode;
              this.formEdit.recordSeq++;
              this.formEdit.dayShift = 1;
              this.formEdit.noticeLeader = 0;
              this.formEdit.pdroomId = "";
              this.formEdit.num = "";
              this.formEdit.roomName = "";
              this.formEdit.voltageA = "";
              this.formEdit.voltageB = "";
              this.formEdit.voltageC = "";
              this.formEdit.currentA = "";
              this.formEdit.currentC = "";
              this.formEdit.remark = "";
              this.$message({
                type: "success",
                message: "提交成功",
              });
              // let params = {
              //   ...this.params,
              //   pageNo: this.currentPage,
              //   pageSize: 10,
              // };
              // this.getkvoperationlist(params);
              //判断是提交 还是下一组按钮
              // 提交
              if(val == 1){
                  this.dialog = false;
                  let params = {
                    ...this.params,
                    pageNo: this.currentPage,
                    pageSize: 10,
                  };
                  this.getkvoperationlist(params);

              }else{
                //下一组
                 this.dialog = true;
                 
                //清空表单
                Object.keys(this.formEdit).map((key)=>{
                  if(key!=='noticeLeader'&&key!=='Inspector'&&key!=='empIds'&&key!=='inspectionTime'&&key!='recordSeq'&&key!='recordCode'){
                     this.formEdit[key] = '' 
                  }
                  
                })
                this.$refs.createForm.clearValidate();
              }
            
              
            } else {
            }
          });
        } else {
        }
      });
    },
    //打开弹窗
    FnOpenDialog(val) {
      console.log(val);
      console.log("===val===");
      //修改
      if (val == 0) {
        this.dialogTitle = "更新巡检记录";
      }
      //新增
      else {
        this.dialogTitle = "新增巡检记录";
        // this.formEdit.inspectionTime = getTime();

        // this.formEdit.inspectionTime = getTime();

        // console.log("====this.formEdit.inspectionTime====");
        //默认 系统时间

        //清空表单
        Object.keys(this.formEdit).map((key) => {
          this.formEdit[key] = "";
        });
        // 默认时间
        this.formEdit.inspectionTime = getTime();
        this.formEdit.recordSeq = 1;
        // 巡检人
        let obj = JSON.parse(localStorage.getItem("userInfo"));
        this.formEdit.empIds = obj.userId;
        this.formEdit.Inspector = obj.name;
         this.formEdit.noticeLeader = '否';

        this.$nextTick(() => {
          // console.log(this.$refs.createForm)
          // console.log('======createForm======')
          this.$refs.createForm.clearValidate();
        });
      }
      //新增还是修改
      this.dialog = true;
    },
    // 导出
    exportExcel() {
      // 需要修改的导出
      const data = {
        pageNo: this.pageNo,
        pageSize: 5000,
        inspectionTime: this.params.value1,
        empId: this.params.empIds,
        roomId: this.params.roomName,
        noticeLeader: this.params.noticeLeader,
      };
      exportMethod("kvOperationRecord", data, "10KV操作室巡检记录");
    },
    modelNameIndex() {
      modelNameIndex("kvTransformerRecord", { pageNo: 1, pageSize: 100 }).then(
        (res) => {}
      );
    },
    FnSearchMember(val) {
      getlists({
        deptId: "",
        emplName: val,
        userType: "1",
      }).then((res) => {
        this.InspectorArr = res.data;
        console.log(this.InspectorArr);
      });
    },
    changeInspector(val) {
      console.log(val);
      this.formEdit.empIds = val;
    },
    newsele() {},
    // 下一组
    FnNext() {
      // 调保存还是next接口
      // 1.校验通过
      this.$refs.createForm.validate((valid) => {
        if (valid) {
          if (this.formEdit.recordCode) {
            console.log("下一组接口");
            kvoperationaddNextLine(this.formEdit).then((res) => {
              console.log(res);
              if (res.code == "200") {
                // this.form.recordCode = res.data.data.recordCode;
                this.formEdit.recordSeq++;
                this.formEdit.dayShift = 1;
                this.formEdit.noticeLeader = 0;
                this.formEdit.pdroomId = "";
                this.formEdit.num = "";
                this.formEdit.roomName = "";
                this.formEdit.voltageA = "";
                this.formEdit.voltageB = "";
                this.formEdit.voltageC = "";
                this.formEdit.currentA = "";
                this.formEdit.currentC = "";
                this.formEdit.remark = "";

                this.dialog = true;
                //清空表单
                Object.keys(this.formEdit).map((key)=>{
                  if(key!=='noticeLeader'&&key!=='Inspector'&&key!=='empIds'&&key!=='inspectionTime'&&key!='recordSeq'&&key!='recordCode'){
                     this.formEdit[key] = '' 
                  }
                  
                })
                this.$refs.createForm.clearValidate();

                // let params = {
                //   ...this.params,
                //   pageNo: this.currentPage,
                //   pageSize: 10,
                // };
                // this.getkvoperationlist(params);
              } else {
              }
            });
          } else {
            console.log("111");
            // 调保存接口
            this.FnSave();
             console.log('222')
          }
        } else {
          // this.$refs.createForm.validate()
          console.log('我走这里来啦~')


          
        }
      });

      // this.dialog = false;
    },
    timefun(data) {
      return utils.formatDate(data, "yyyy-MM-dd HH:mm:ss");
    },
    //改变页数
    currentChange(val) {
      console.log(val);

      // this.pageNo = pageNo;
      let params = {
        ...this.params,
        pageNo: val,
        pageSize: 10,
      };
      this.getkvoperationlist(params);
    },
    // 查询接口
    getkvoperationlist(params) {
      kvoperationlist(params).then((res) => {
        this.tableData = res.data.list;
        this.total = res.data.total;
      });
    },
    //修改
    FnUpdate() {
      this.$refs.createForm.validate((valid) => {
        if (valid) {
          this.formEdit.noticeLeader == "是"
            ? (this.formEdit.noticeLeader = 1)
            : (this.formEdit.noticeLeader = 0);
            this.formEdit.dayShift == "夜班"
            ? (this.formEdit.dayShift = 0)
            : (this.formEdit.dayShift = 1);
          kvoperationupdate(this.formEdit).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: "更新成功",
                type: "success",
              });
              this.dialog = false;
              let params = {
                ...this.params,
                pageNo: this.currentPage,
                pageSize: 10,
              };

              this.getkvoperationlist(params);
            }
          });
        }
      });
    },
    //打开编辑弹窗 调详情接口
    handleClick(val) {
      console.log(JSON.parse(localStorage.getItem("userInfo")));
      console.log("99999");
      this.FnOpenDialog(0);
      //调详情接口
      console.log(val.id);
      kvoperationGetById(val.id).then((res) => {
       
        if (res.code == "200") {
          // 巡检日期
          this.formEdit.inspectionTime = utils.formatDate(
            res.data.inspectionTime,
            "yyyy-MM-dd HH:mm:ss"
          );
          console.log(res)
          console.log('===res====')
           this.formEdit = {
             ...res.data,
             noticeLeader:res.data.noticeLeader?'是':'否',
             Inspector:res.data.empNames,
             inspectionTime: utils.formatDate(res.data.inspectionTime,"yyyy-MM-dd HH:mm:ss"),
             dayShift:res.data.dayShift?'白班':'夜班'
           }
            
          // //给表单赋值
          // this.formEdit.Inspector = res.data.empNames;
          // this.formEdit.empIds = res.data.empIds;
          // // 巡检人赋值
          // // this.formEdit.Inspector.push({
          // //   id:obj.userId,
          // //   emplName:obj.name
          // // });

          // this.formEdit.id = res.data.id;
          
          // this.empIdsList.push({
          //   empIds: this.formEdit.empIds,
          //   empNames: this.formEdit.Inspector,
          // });
          // console.log(this.formEdit.id);
          // console.log("====this.formEdit.id====");

          // // 巡检位置
          // this.formEdit.roomName = res.data.roomName;
          // this.formEdit.roomId = res.data.roomId;
          // console.log(res.data.roomName);
          // console.log("0000000");
          // console.log(res.data.roomId);

          // //是否上报班组长
          // this.formEdit.noticeLeader = res.data.noticeLeader ? "是" : "否";
          // console.log(this.formEdit)
          //  console.log('====this.formEdit====')
        }
        // console.log(this.formEdit.Inspector + "sfsdf");
      });
    },
    FnQuery() {
      let params = {
        ...this.params,
        pageNo: 1,
        pageSize: 10,
      };

      this.currentPage = 1;

      this.getkvoperationlist(params);
    },
    // 重置
    FnReset() {
      Object.keys(this.params).forEach((key) => {
        this.params[key] = "";
      });
      this.currentPage = 1;
    },
    // 已处理
    FnDeal(val) {
      console.log(val);
      console.log("===val==");
      this.$confirm("请确认异常是否已处理完毕?", "确认提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          console.log("确定");
          kvoperationDealAllException({ recordId: val.id })
            .then((res) => {
              if (res.code == 200) {
                let params = {
                  ...this.params,
                  pageSize: 10,
                  pageNo: this.currentPage,
                };
                this.getkvoperationlist(params);
                this.$message({
                  type: "success",
                  message: "处理成功!",
                });
              }
            })
            .catch((error) => {
              console.log(error);
            });
        })
        .catch(() => {
          console.log("取消");
        });
    },
    handleSizeChange() {},
    handleCurrentChange() {},
  },
};
</script>
<style lang="scss">
.kvtransformer {
 .el-form--inline .el-form-item__label{
    padding-left: 46px;
  }
  .kvtransformer-Query {
    margin-top: 40px;
  }
}
</style>
<style lang="scss" scoped>
.c-main-make {
  margin-left: 35px;
  height: 233px;
  background: #fff;
  margin-right: 35px;
  margin-bottom: 35px;
  position: relative;
  overflow: hidden;
  border: 1px #dcdee0 solid;
}
.c-main-show {
  margin-left: 35px;
  background: #fff;
  margin-right: 35px;
  margin-bottom: 35px;
  position: relative;
  overflow: hidden;
  border: 1px #dcdee0 solid;
}
.title-text {
  width: 100%;
  height: 50px;
  border-bottom: 1px #dcdee0 solid;
  font-family: "微软雅黑 Bold", "微软雅黑 Regular", 微软雅黑, sans-serif;
  font-weight: 700;
  color: #666666;
  line-height: 50px;
  padding-left: 25px;
}
.fenye {
  display: flex;
  justify-content: right;
}
</style>
